package com.example.forumsystem.demos.web.mapper;

import com.example.forumsystem.demos.web.model.MessageInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageInfoMapper {
    int insert(MessageInfo row);

    int insertSelective(MessageInfo row);

    MessageInfo selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(MessageInfo row);

    int updateByPrimaryKey(MessageInfo row);

    /**
     * 查找未读信息的次数
     * @param receiveUserId 传来的发送者id
     * @return 未读信息的次数
     */
    @Select("select count(*) from t_message " +
            "where state = 0 " +
            "and deleteState = 0 and receiveUserId = #{receiveUserId}")
    Integer selectUnreadCount(Long receiveUserId);

    List<MessageInfo> selectByReceiveUserId(@Param("receiveUserId") Long receiveUserId);
}